package com.litong.rms.dao.impl;

import java.util.List;

import com.litong.rms.bean.RoleAuth;
import com.litong.rms.dao.RoleAuthDao;

public class RoleAuthDaoImpl extends BaseDaoImpl implements RoleAuthDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6006508668358135367L;

	public void addRoleAuth(RoleAuth roleAuth) {
		save(roleAuth);

	}

	public void deleteRoleAuth(RoleAuth roleAuth) {
		delete(roleAuth);

	}

	public RoleAuth findRoleAuth(RoleAuth roleAuth) {
		Integer roleId = roleAuth.getRoleId();
		Integer authId = roleAuth.getAuthId();
		String queryString = "from RoleAuth where authId = ? and roleId = ?"; 
		Object[] values = new Object[2];
		values[0] = authId;
		values[1] = roleId;
		List<RoleAuth> roleAuthList = this.find(queryString, values);
		if(roleAuthList!=null&&!roleAuthList.isEmpty()){
			return roleAuthList.get(0);
		}
		return null;
	}

	public <T> List<T> getRoleAuthList() {
		// TODO Auto-generated method stub
		return null;
	}

	public void updateRoleAuth(RoleAuth roleAuth) {
		// TODO Auto-generated method stub

	}

	@SuppressWarnings("unchecked")
	public List<RoleAuth> getRoleAuthList(int roleId) {
		Integer value = roleId;
		String queryString = "from RoleAuth where roleId = ?";
		List<RoleAuth> roleAuthList = this.find(queryString, value);
		return roleAuthList;
	}

	public void deleteRoleAuthByRoleId(int roleId){
		StringBuffer queryString = new StringBuffer();
		queryString.append("delete from roleAuth where roleId = "+roleId);
		this.executeBySQL(queryString.toString());
	}
	
}
